/*
 * @Autor: dingxiaolin
 * @Date: 2021-06-02 13:12:43
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2021-07-21 16:44:20
 */
import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'

import { createRouterGuards } from './router-guards'
import 'nprogress/css/nprogress.css' // 进度条样式

import staticRoutes from './modules/staticRoutes'
import { errorRoutes, notFound } from './modules/error'
import common from '@/router/common'
import { App } from 'vue'

export const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Layout',
        redirect: '/welcome',
        component: () => import('@/layout/index.vue'),
        meta: {
            title: '首页'
        },
        children: [...common]
    },
    ...staticRoutes,
    errorRoutes
]

const router = createRouter({
    // process.env.BASE_URL
    history: createWebHistory(''),
    routes,
    strict: true,
    scrollBehavior: () => ({ left: 0, top: 0 }),
})

export function setupRouter(app: App) {
    app.use(router)
    // 创建路由守卫
    createRouterGuards(router)
}
export default router
